
$(document).ready(function () {
    $("#denglu").click(function () {
        var name=$("#username").val();
        $.ajax({
            type: "post",
            url: "/login/getUser",
            data: {
                name: name,
            },
            dataType: "json",
            success: function (data) {
                checkUser(data);
            },
            error: function (data) {
                if(name==null||name==""){
                    alert("用户名不能为空！")
                } else {
                    alert("用户未注册！")

                }

            }

        })

    })

    function checkUser(json) {
        var name=$("#username").val();
        var password = $("#password").val();
        if ( password == null || password == "") {
            alert("请输入密码！");
        }else {
            if (json.name == name && json.password == password) {
                if (json.type == "teacher") {
                    window.location.href = "tMain";
                } else {
                    window.location.href = "sMain";
                }
            }else {
                alert("密码错误！")
            }
        }
    }
})

function keyLogin(){
    if (event.keyCode==13)  //回车键的键值为13
        document.getElementById("denglu").click(); //调用登录按钮的登录事件
}


